<template>
  <div>
    <el-button round @click="dialogVisible = true">添加</el-button>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="ID">
          <el-input v-model="form.id"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="form.sex" placeholder="男">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="form.age"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sub"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="ID" width="180"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="sex" label="性别" width="180"> </el-table-column>
      <el-table-column prop="age" label="年龄"> </el-table-column>
    </el-table>

    <!-- <el-dropdown trigger="click">
      <span class="el-dropdown-link">
        性别<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item>
          <el-checkbox label="男" checked name="type"></el-checkbox>
        </el-dropdown-item>
        <el-dropdown-item>
          <el-checkbox label="女" name="type"></el-checkbox>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown> -->
  </div>
</template>

  <script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      form: {
        id:'',
        name: "",
        age:'',
        sex:'男'
      },
    };
  },
  methods: {
    moun() {
      axios.get("http://localhost:3000/data").then((res) => {
        this.tableData = res.data;
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
          _;
        })
        .catch((_) => {
          _;
        });
    },
    onSubmit() {
      console.log("submit!");
    },
    sub(){
      this.dialogVisible = false;
      axios.post('http://localhost:3000/post',{
        data:this.form
      }).then(()=>{
        this.moun();
      })
    }
  },
  mounted() {
    this.moun();
  },
};
</script>
<style>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.demonstration {
  display: block;
  color: #8492a6;
  font-size: 14px;
  margin-bottom: 20px;
}
</style>